<?php
/*
 * Created by generator
 *
 */

class Editactivite extends Controller {

	function Editactivite(){
		parent::Controller();
		$this->load->model('activite_model');
		$this->load->model('niveau_model');
		$this->load->model('trancheAge_model');
		$this->load->model('saison_model');
		$this->load->model('professeur_model');
		$this->load->model('adherent_model');
		$this->load->model('Situation_model');
		
		$this->load->library('session');
		$this->load->helper('url');
	}


	/**
	 * Affichage des infos
	 */
	public function index($actidact, $orderBy = null){
		$model = activite_model::getactivite($this->db, $actidact);
		$data['niveaux'] = niveau_model::getAllniveaus($this->db); 
		$data['tranchesAges'] = trancheAge_model::getAlltrancheAges($this->db);
		$data['saisons'] = saison_model::getAllsaisons($this->db);
		$data['situations'] = Situation_model::getAllSituations($this->db);
		$data['professeurs'] = professeur_model::getAllprofesseurs($this->db, /*order by*/"prolbnom");
		$data['activite'] = $model;
		
		$data['adherents'] = adherent_model::getAllAdherentsForActivite($this->db, $actidact, $orderBy);
		if( $orderBy != null ) {
			$data['goto'] = "adherents";
		}
		
		// statistiques
		$data['chiffreAffaires'] = $model->getChiffreAffaires($this->db);
		
		$this->load->view('editactivite_view',$data);
	}

	/**
	 * Sauvegarde des modifications
	 */
	public function save(){
		// Mise a jour des donnees en base
		$model = new activite_model();
		$model->actidact = $this->input->post('actidact');
		$model->actlblib = $this->input->post('actlblib'); 
		$model->actidniv = $this->input->post('actidniv'); 
		$model->actidtra = $this->input->post('actidtra'); 
		$model->actidsai = $this->input->post('actidsai'); 
		$model->actidpro = $this->input->post('actidpro'); 
		$model->actlbjou = $this->input->post('actlbjou'); 
		$model->actlbhdb = $this->input->post('actlbhdb'); 
		$model->actlbdfn = $this->input->post('actlbdfn'); 
		$model->actfgmai = $this->input->post('actfgmai'); 
		$model->actidsit = $this->input->post('actidsit'); 
		$model->actmocot = $this->input->post('actmocot'); 
		$model->update($this->db);

		$this->session->set_flashdata('message', 'activite mis a jour');

		redirect('listactivites/index'); 
	}
	
}
?>
